package com.szs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.szs.common.R;
import com.szs.dto.DishDto;
import com.szs.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     *
     * @param dishDto
     * @return
     */
    @PostMapping
    public R<DishDto> save(@RequestBody DishDto dishDto) {
        return dishService.saveWithFlavor(dishDto);
    }

    @GetMapping("/page")
    public R<Page> page(int page, int pageSize, String name) {
        return dishService.page(page, pageSize, name);
    }

    /**
     * 菜品删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    public R<String> remove(@RequestParam List<Long> ids) {
        log.info("被选中删除的菜品id：{}", ids);
        return dishService.remove(ids);
    }

    /**
     * 菜品的售卖状态
     *
     * @param type
     * @param ids
     * @return
     */
    @PostMapping("status/{type}")
    public R<String> saleStatus(@PathVariable int type, @RequestParam List<Long> ids) {
        log.info("状态为：{}，isd：{}", type, ids);
        return dishService.saleStatus(type, ids);
    }

}
